package com.ala4.oxcafe.boot.utils;

import com.ala4.oxcafe.export.ExportPage;
import jakarta.servlet.http.HttpServletResponse;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;

/**
 * 工具类
 *
 * @author PING
 * @version 1.0
 * @date 2024/12/20 11:39
 */
public class ExcelAopUtil {

    private ExcelAopUtil() {
    }

    public static HttpServletResponse getAopArgsHttpServletResponse(ProceedingJoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (arg instanceof HttpServletResponse argResponse) {
                return argResponse;
            }
        }
        return null;
    }

    public static <T> T getAopArgs(ProceedingJoinPoint joinPoint, Class<T> tClass) {
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (arg.getClass().equals(tClass)) {
                return (T) arg;
            }
        }
        return null;
    }

    public static ExportPage getAopArgsPageRequest(ProceedingJoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (arg instanceof ExportPage exportPage) {
                return exportPage;
            }
        }
        return null;
    }

    public static Method getAopArgsMethod(Signature signature) {
        MethodSignature methodSignature = (MethodSignature) signature;
        return methodSignature.getMethod();
    }
}
